package com.laputa.model.manager;

import java.util.*;

import com.laputa.dao.*;
import com.laputa.dao.model.*;

public class FriendManager {

	private UserDao userDao;
	private FriendrelationDao friendRelationDao;
	private CityDao cityDao;
	private GroundDao groundDao;
	private BuildingDao buildingDao;
	
	public void setUserDao(UserDao pd){
		this.userDao = pd;
	}
	
	public void setCityDao(CityDao pd){
		this.cityDao = pd;
	}

	public void setGroundDao(GroundDao pd){
		this.groundDao = pd;
	}
	
	public void setBuildingDao(BuildingDao pd){
		this.buildingDao = pd;
	}
	
	public void setFriendRelationDao(FriendrelationDao friendRelationDao){
		this.friendRelationDao = friendRelationDao;
	}
	
	public void delete(String id) {
		userDao.delete(new Long(id));
	}
	
	public List getAll() {
		return userDao.getAll();
	}
	
	public List getFriendListObject(String userID){
		List friendrelationList = this.friendRelationDao.getFriendrelationListByHost(new Long(userID));
		ArrayList friendList = new ArrayList();
		for (int i = 0; i <  friendrelationList.size(); ++i){
			User user = userDao.getUser(((Friendrelation)friendrelationList.get(i)).getGuest());
			//TODO: spring factory?
			com.laputa.model.User userObject = new com.laputa.model.User(user);
			friendList.add(userObject);
		}
		return friendList;			
	}
	
	public void addFriend(String userID, String friendName) {
		User user = userDao.getUser(friendName);
		Friendrelation fr = new Friendrelation();
		fr.setHost(new Long(userID));
		fr.setGuest(user.getId());
		this.friendRelationDao.save(fr);
	}
}
